using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace QUAN_LY_NGAN_HANG_CAU_HOI_TRAC_NGHIEM
{
    public class QuyenDAL
    {

        private Guid _maQuyen;

        public Guid MaQuyen
        {
            get { return _maQuyen; }
            set { _maQuyen = value; }
        }

        private string _ghiChu;

        public string GhiChu
        {
            get { return _ghiChu; }
            set { _ghiChu = value; }
        }
        
        public static QuyenDAL LayQuyen_Ma(Guid ma)
        {
            using (SqlConnection cn = new SqlConnection(Globals.ConnectionString))
            {
                var en = new QuyenDAL();
                SqlCommand cmd = new SqlCommand("uspLayQuyen_Ma", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@ma", SqlDbType.UniqueIdentifier).Value = ma;
                cn.Open();
                IDataReader rd = cmd.ExecuteReader();
                if (rd != null)
                {
                    while (rd.Read())
                    {
                        en.MaQuyen = (Guid) rd["MaQuyen"];
                        en.GhiChu = (string) rd["GhiChu"];
                    }
                }
                return en;
            }
        }
        public static List<QuyenDAL> LayTatCaQuyen()
        {
            var lst = new List<QuyenDAL>();
            using (var con = new SqlConnection(Globals.ConnectionString))
            {
                var cmd = new SqlCommand("usp_LayTatCaQuyen", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                IDataReader rd = cmd.ExecuteReader();
                if (rd != null)
                {
                    while (rd.Read())
                    {
                        var cn = new QuyenDAL();
                        cn.MaQuyen = (Guid)rd["MaQuyen"];
                        cn.GhiChu = (string)rd["GhiChu"];
                        lst.Add(cn);
                    }
                }
            }
            return lst;
        }
    }
}